#!/usr/bin/php
<?php
/*
 * Copyright © 2020 Anonymous
 * This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See the COPYING file for more details.
 */

if ($argc != 2)
{
	fwrite(STDERR, "Usage: decoder.php [license]" . PHP_EOL);
	fwrite(STDERR, "license is license to be decoded" . PHP_EOL);
	exit();
}

$license = trim($argv[1]);

$p = 13;
$x = 5; //rand(2, $p-1);
$shift = $x;

$blocks = explode(' ', $license);
$res = '';


foreach($blocks as $block)
{	
	$m = '';
	for($i = 0; $i < strlen($block); $i += 2)
	{
		$a = base_convert($block[$i], 36, 10) - ($i / 2 + $shift) % 27;
		$b = base_convert($block[$i + 1], 36, 10) - ($i / 2 + $shift) % 24;
			
		$m .= ($b * (pow($a, $p - $x - 5) ) ) % $p;
	}
	$m = base_convert($m, 10, 16);
	for ($a = 0; $a < strlen($m); $a += 2)
		$res .= chr(hexdec( $m{$a}.$m{ $a+1 }) );
	$shift += $x;
}

$key = explode('#', $res, 3);
$key[0] = explode(',', $key[0]);

print_r($key);

print PHP_EOL;
